﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HRM.HRMServiceProxy;
using HRM.Utilities;
using System.IO;
using WeifenLuo.WinFormsUI.Docking;

namespace HRM
{
    public partial class frmImportData : DockContent
    {
        public frmImportData()
        {
            InitializeComponent();
        }

        private void btnImport_Click(object sender, EventArgs e)
        {
            string _Path = "";
            string _FileName = "";
            string[] _FolderName = null;
            int i = 0;
            int _HeaderID = 0;
            int _DetailID = 0;
            int _EmployeeID = 0;
            int _DepartmentID = 0;
            decimal _PaidAmount = 0;
            decimal _AmountRemain = 0;
            decimal _BHYT_PaidAmount = 0;
            decimal _BHTN_PaidAmount = 0;
            decimal _BHXH_PaidAmount = 0;
            decimal _BHYT_ThuaKyTruoc = 0;
            decimal _BHYT_ThieuKyTruoc = 0;
            decimal _BHTN_ThuaKyTruoc = 0;
            decimal _BHTN_ThieuKyTruoc = 0;
            decimal _BHXH_ThuaKyTruoc = 0;
            decimal _BHXH_ThieuKyTruoc = 0;
            EmployeeClient _wcfEmployee = Service.Employee();
            EmployeeInfo _EmployeeInfo;
            PremiumClient _wcfPremium = Service.Premium();
            PremiumInfo _PremiumInfo;
            HeaderClient _wcfHeader = Service.Header();
            HeaderInfo _HeaderInfo;
            DetailClient _wcfDetail = Service.Detail();
            DetailInfo _DetailInfo;
            PositionDetailClient _wcfPD = Service.PositionDetail();
            PositionDetailInfo _PDInfo;
            SalaryFundClient _wcfFund = Service.SalaryFund();
            SalaryFundInfo _FundInfo;
            DataSet ds = new DataSet();
            DataSet dsHeader = new DataSet();
            DepartmentClient _wcfDepartment = Service.Department();
            UNCClient _wcfUNC = Service.UNC();
            UNCInfo _UNCInfo;
            DataTable _dtLast = new DataTable();

            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                _Path = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.LastIndexOf("\\"));
                _FolderName = Directory.GetFiles(_Path, "*.DBF");
                foreach (string _Name in _FolderName)
                {
                    _FileName = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);
                    //_FileName = _Name;
                    OleDbConnection _Conn = new OleDbConnection("Provider = vfpoledb; Data Source = " + _Path + "; Collating Sequence=general");
                    OleDbCommand _dbCmd;
                    OleDbCommand _dbCmd1 = new OleDbCommand();
                    _dbCmd = new OleDbCommand("SELECT * FROM " + _FileName, _Conn);
                    if (_FileName == "HSC47.DBF")
                    {
                        _dbCmd1 = new OleDbCommand("SELECT DISTINCT keysl,madvi,maqt,ngayct,tyle_bhxh,tyle_bhyt,tyle_bhtn,mltt,loaidt FROM " + _FileName, _Conn);
                    }
                    try
                    {
                        _Conn.Open();
                        OleDbDataAdapter da = new OleDbDataAdapter(_dbCmd);
                        da.Fill(ds);
                        if (_FileName == "HSC47.DBF")
                        {
                            OleDbDataAdapter da1 = new OleDbDataAdapter(_dbCmd1);
                            da1.Fill(dsHeader);
                        }
                        dgvUser1.DataSource = ds.Tables[0];
                    }
                    finally
                    {
                        _Conn.Close();
                    }
                    DataTable dtdept = _wcfDepartment.Department_GetAllWithBranch(Program.intBranchID).Tables[0];
                    if (dtdept.Rows.Count > 0)
                        _DepartmentID = Convert.ToInt32(dtdept.Rows[0]["DEPARTMENT_ID"]);
                    if (_FileName.Contains("HOSOCB.DBF") || _FileName.Contains("HOSOCN.DBF"))
                    {
                        //Insert bang HRM_Employee:
                        #region Ho so nhan vien
                        //for (i = 0; i < ds.Tables[0].Rows.Count; i++)
                        //{
                        //    _EmployeeID = 0;
                        //    _EmployeeInfo = new EmployeeInfo();
                        //    _EmployeeInfo.FirstName = UnicodeConvert.TCVN3ToUnicode(ds.Tables[0].Rows[i]["Ten"].ToString().Trim());
                        //    _EmployeeInfo.LastName = UnicodeConvert.TCVN3ToUnicode(ds.Tables[0].Rows[i]["Ho"].ToString().Trim());
                        //    _EmployeeInfo.CardNo = "";
                        //    int _Code = 0;
                        //    EmployeeInfo _empCode = new EmployeeInfo();
                        //    _empCode = _wcfEmployee.Employee_GetMaxEmployeeCode(Program.intBranchID);
                        //    if (_empCode == null)
                        //        _Code = 0;
                        //    else
                        //        _Code = Convert.ToInt32(_empCode.Code.Trim());
                        //    _EmployeeInfo.Code = (_Code + 1).ToString("00000");
                        //    _EmployeeInfo.Alias = "";
                        //    _EmployeeInfo.Education = 0;
                        //    if (ds.Tables[0].Rows[i]["ngaysinh"] != null)
                        //        _EmployeeInfo.DateOfBirth = Convert.ToDateTime(ds.Tables[0].Rows[i]["ngaysinh"].ToString());
                        //    else
                        //        _EmployeeInfo.DateOfBirth = DateTime.MinValue;
                        //    _EmployeeInfo.EthlicID = 1;//ds.Tables[0].Rows[i]["dantoc"].ToString()
                        //    _EmployeeInfo.MaterialStatusID = 1;
                        //    _EmployeeInfo.ReligionID = 1;
                        //    _EmployeeInfo.Sex = Convert.ToBoolean(ds.Tables[0].Rows[i]["gioitinh"]);
                        //    _EmployeeInfo.PlaceOfBirth = "";
                        //    _EmployeeInfo.Address = UnicodeConvert.TCVN3ToUnicode(ds.Tables[0].Rows[i]["diachi"].ToString().Trim());
                        //    _EmployeeInfo.Phone = "";
                        //    _EmployeeInfo.Nationality = 1;
                        //    _EmployeeInfo.PassportNo = "";
                        //    _EmployeeInfo.PassportIssueDate = DateTime.MinValue;
                        //    _EmployeeInfo.PassportExpireDate = DateTime.MinValue;
                        //    _EmployeeInfo.IDCardNo = ds.Tables[0].Rows[i]["socmnd"].ToString().Trim();
                        //    if (ds.Tables[0].Rows[i]["ngaycmnd"] != null)
                        //        _EmployeeInfo.IDCardIssueDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["ngaycmnd"].ToString());
                        //    else
                        //        _EmployeeInfo.IDCardIssueDate = DateTime.MinValue;
                        //    _EmployeeInfo.IDCardIssueAuthority = UnicodeConvert.TCVN3ToUnicode(ds.Tables[0].Rows[i]["noicap"].ToString().Trim());
                        //    _EmployeeInfo.SIBookNo = ds.Tables[0].Rows[i]["sobhxh"].ToString().Trim();
                        //    _EmployeeInfo.SIBookIssueDate = DateTime.MinValue;
                        //    _EmployeeInfo.SIBookIssueAuthority = ds.Tables[0].Rows[i]["ma_tinh"].ToString().Trim();
                        //    _EmployeeInfo.BankAccountNo = "";
                        //    _EmployeeInfo.BankName = "";
                        //    _EmployeeInfo.StartDate = DateTime.MinValue;
                        //    _EmployeeInfo.EndDate = DateTime.MinValue;
                        //    _EmployeeInfo.Description = "";
                        //    _EmployeeInfo.IsOfficer = true;
                        //    _EmployeeInfo.IsQuit = false;
                        //    _EmployeeInfo.MedicalNo = ds.Tables[0].Rows[i]["sokcb"].ToString().Trim();
                        //    _EmployeeInfo.MedicalDate = DateTime.MinValue;
                        //    _EmployeeInfo.MedicalPlace = ds.Tables[0].Rows[i]["ma_bv"].ToString().Trim();
                        //    _EmployeeInfo.Type = false;
                        //    _EmployeeInfo.LeaveWorkID = 0;
                        //    _EmployeeInfo.UnemployIns = false;
                        //    _EmployeeInfo.UnemployInsDate = DateTime.MinValue;
                        //    _EmployeeInfo.Specialist = "";
                        //    _EmployeeInfo.Culture = "";
                        //    _EmployeeInfo.IsInitial = true;
                        //    if (_wcfEmployee.Employee_CheckExist(0, _EmployeeInfo.Code, Program.intBranchID) == 0)
                        //    {
                        //        if (_wcfEmployee.Employee_CheckExistSIBookNo(0, _EmployeeInfo.SIBookNo, Program.intBranchID) == 0)
                        //        {
                        //            _EmployeeID = _wcfEmployee.Employee_Insert(_EmployeeInfo);
                        //            _PDInfo = new PositionDetailInfo();
                        //            _PDInfo.DepartmentID = _DepartmentID;
                        //            _PDInfo.EmployeeID = _EmployeeID;
                        //            if (ds.Tables[0].Columns.Contains("thang"))
                        //                _PDInfo.BeginDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["thang"].ToString().Substring(4, 2) + "/" + ds.Tables[0].Rows[i]["thang"].ToString().Substring(0, 4));
                        //            else
                        //                _PDInfo.BeginDate = DateTime.Now.Date;
                        //            _PDInfo.EndDate = DateTime.MinValue;
                        //            _PDInfo.IsActive = true;
                        //            _PDInfo.PositionID = 29;
                        //            _PDInfo.BasicSalary = 0;
                        //            _PDInfo.PositionAllowance = 0;
                        //            _PDInfo.TotalSalary = 0;
                        //            _PDInfo.GradeID = 55;
                        //            _PDInfo.LevelID = 1;
                        //            _PDInfo.MinSalary = 0;
                        //            if (ds.Tables[0].Columns.Contains("hsl"))
                        //            {
                        //                _PDInfo.BasicFactor = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["hsl"].ToString());
                        //                _PDInfo.PositionFactor = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["pc1"].ToString());
                        //            }
                        //            else
                        //            {
                        //                _PDInfo.BasicFactor = 0;
                        //                _PDInfo.PositionFactor = 0;
                        //            }
                        //            _PDInfo.OtherFactor = 0;
                        //            _PDInfo.PositionAllowance = 0;
                        //            _PDInfo.LunchAllowance = 0;
                        //            _PDInfo.TelephoneAllowance = 0;
                        //            _PDInfo.LaterInsurance = false;
                        //            _PDInfo.Job = "";
                        //            _PDInfo.DatePositionBegin = DateTime.MinValue;
                        //            _PDInfo.DatePositionEnd = DateTime.MinValue;
                        //            _PDInfo.Description = "";
                        //            _wcfPD.PositionDetail_Insert(_PDInfo);
                        //        }
                        //    }
                        //}
                        #endregion
                    }
                    else if (_FileName.Contains("HSC47.DBF"))
                    {
                        #region Cap nhat tang giam BHXH
                        
                        //foreach (DataRow drHeader in dsHeader.Tables[0].Rows)
                        //{
                        //    //Insert bang HRM_Header:
                        //    _HeaderID = 0;
                        //    _HeaderInfo = new HeaderInfo();
                        //    _HeaderInfo.BranhCode = drHeader["madvi"].ToString().Trim();
                        //    _HeaderInfo.Date = Convert.ToDateTime(drHeader["ngayct"].ToString().Substring(0, 10));
                        //    _HeaderInfo.Month = Convert.ToInt32(drHeader["maqt"].ToString().Substring(4, 2));
                        //    _HeaderInfo.Year = Convert.ToInt32(drHeader["maqt"].ToString().Substring(0, 4));
                        //    _HeaderInfo.Period = Convert.ToInt32(drHeader["maqt"].ToString().Substring(6, 2));
                        //    _HeaderInfo.Social = Convert.ToDecimal(drHeader["tyle_bhxh"]);
                        //    _HeaderInfo.Medical = Convert.ToDecimal(drHeader["tyle_bhyt"]);
                        //    _HeaderInfo.Unemployed = Convert.ToDecimal(drHeader["tyle_bhtn"]);
                        //    _HeaderInfo.BasicSalary = Convert.ToDecimal(drHeader["mltt"]);
                        //    _HeaderInfo.IsInitial = true;
                        //    _HeaderInfo.Type = Convert.ToString(drHeader["loaidt"]);
                        //    if (!_wcfHeader.Header_CheckExist(0, _HeaderInfo.BranhCode, _HeaderInfo.Date))
                        //        _HeaderID = _wcfHeader.Header_Insert(_HeaderInfo);
                        //    for (i = 0; i < ds.Tables[0].Rows.Count; i++)
                        //    {
                        //        //Insert bang HRM_Detail:
                        //        if (ds.Tables[0].Rows[i]["keysl"].ToString() == drHeader["keysl"].ToString())
                        //        {

                        //            _DetailID = 0;
                        //            _DetailInfo = new DetailInfo();
                        //            _DetailInfo.DocumentID = _HeaderID;
                        //            _DetailInfo.InsBookNo = ds.Tables[0].Rows[i]["sobhxh"].ToString().Trim();
                        //            _DetailInfo.EmployeeCode = _wcfEmployee.Employee_GetInfoBySIBookNo(_DetailInfo.InsBookNo).Code;
                        //            _DetailInfo.FromDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["tuthang"].ToString().Trim().Substring(4, 2) + "/" + ds.Tables[0].Rows[i]["tuthang"].ToString().Trim().Substring(0, 4));
                        //            _DetailInfo.ToDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["denthang"].ToString().Trim().Substring(4, 2) + "/" + ds.Tables[0].Rows[i]["denthang"].ToString().Trim().Substring(0, 4));
                        //            _DetailInfo.InsTypeCode = ds.Tables[0].Rows[i]["pa"].ToString().Trim();
                        //            _DetailInfo.SocialRate = Convert.ToDecimal(ds.Tables[0].Rows[i]["tyle_bhxhd"]);
                        //            _DetailInfo.MedicalRate = Convert.ToDecimal(ds.Tables[0].Rows[i]["tyle_bhytd"]);
                        //            _DetailInfo.UnemployedRate = Convert.ToDecimal(ds.Tables[0].Rows[i]["tyle_bhtnd"]);
                        //            _DetailInfo.OldBasicFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["hsl_dk"]);
                        //            _DetailInfo.OldPositionFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc1_dk"]);
                        //            _DetailInfo.OldOverFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc2_dk"]);
                        //            _DetailInfo.OldJobFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc3_dk"]);
                        //            _DetailInfo.OldAreaFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc4_dk"]);
                        //            _DetailInfo.NewBasicFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["hsl"]);
                        //            _DetailInfo.NewPositionFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc1"]);
                        //            _DetailInfo.NewOverFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc2"]);
                        //            _DetailInfo.NewJobFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc3"]);
                        //            _DetailInfo.NewAreaFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc4"]);
                        //            _DetailInfo.RegionCode = ds.Tables[0].Rows[i]["ma_tinh"].ToString().Trim();
                        //            _DetailInfo.HospitalCode = ds.Tables[0].Rows[i]["ma_bv"].ToString().Trim();
                        //            _DetailInfo.NewAmount = Convert.ToDecimal(ds.Tables[0].Rows[i]["ml_dk"]);
                        //            _DetailInfo.OldAmount = Convert.ToDecimal(ds.Tables[0].Rows[i]["ml"]);
                        //            _DetailInfo.Type = ds.Tables[0].Rows[i]["loaidt"].ToString().Trim();
                        //            _DetailInfo.TakeCard = Convert.ToBoolean(ds.Tables[0].Rows[i]["the_bhyt"]);
                        //            if (!_wcfDetail.Detail_Exist(0, _DetailInfo.InsBookNo, _DetailInfo.FromDate, _DetailInfo.ToDate, _DetailInfo.InsTypeCode))
                        //                _DetailID = _wcfDetail.Detail_Insert(_DetailInfo);
                        //        }
                        //    }
                        //}
                        #endregion
                    }
                    //else if (_FileName.Contains("HISTORY") || _FileName.Contains("QTBHXH"))
                    else if (_FileName.Contains("QTBHXH.DBF"))
                    {
                        #region Qua trinh tham gia truoc day
                        //for (i = 0; i < ds.Tables[0].Rows.Count; i++)
                        //{
                        //    //Insert bang HRM_Premium:u
                        //    _PremiumInfo = new PremiumInfo();
                        //    _PremiumInfo.SIBookNo = ds.Tables[0].Rows[i]["sobhxh"].ToString().Trim();
                        //    _PremiumInfo.EmployeeID = _wcfEmployee.Employee_GetInfoBySIBookNo(_PremiumInfo.SIBookNo).ID;
                        //    if (_FileName.Contains("HISTORY"))
                        //    {
                        //        _PremiumInfo.FromDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["tuthang"].ToString().Substring(4, 2) + "/" + ds.Tables[0].Rows[i]["tuthang"].ToString().Substring(0, 4));
                        //        _PremiumInfo.ToDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["denthang"].ToString().Substring(4, 2) + "/" + ds.Tables[0].Rows[i]["denthang"].ToString().Substring(0, 4));
                        //    }
                        //    else
                        //    {
                        //        _PremiumInfo.FromDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["tuthang"].ToString().Substring(0, 2) + "/" + ds.Tables[0].Rows[i]["tuthang"].ToString().Substring(2, 4));
                        //        _PremiumInfo.ToDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["denthang"].ToString().Substring(0, 2) + "/" + ds.Tables[0].Rows[i]["denthang"].ToString().Substring(2, 4));
                        //    }
                        //    _PremiumInfo.WorkUnit = UnicodeConvert.TCVN3ToUnicode(ds.Tables[0].Rows[i]["madvi"].ToString().Trim());
                        //    _PremiumInfo.WorkName = UnicodeConvert.TCVN3ToUnicode(ds.Tables[0].Rows[i]["tendvi"].ToString().Trim());
                        //    _PremiumInfo.Job = UnicodeConvert.TCVN3ToUnicode(ds.Tables[0].Rows[i]["nghenghiep"].ToString().Trim());
                        //    _PremiumInfo.Type = ds.Tables[0].Rows[i]["loaidt"].ToString().Trim();
                        //    _PremiumInfo.Salary = Convert.ToDecimal(ds.Tables[0].Rows[i]["ml"]);
                        //    _PremiumInfo.BasicSalary = 0;
                        //    _PremiumInfo.BasicFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["hsl"]);
                        //    _PremiumInfo.PositionFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc1"]);
                        //    _PremiumInfo.SeniorityFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc2"]);
                        //    _PremiumInfo.OverSeniorityFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc3"]);
                        //    _PremiumInfo.AreaFactor = Convert.ToDecimal(ds.Tables[0].Rows[i]["pc4"]);
                        //    DateTime _FromDate = _PremiumInfo.FromDate;
                        //    DateTime _ToDate = _PremiumInfo.ToDate;
                        //    _PremiumInfo.MonthNo = UISetting.GetMonth(_FromDate, _ToDate) + 1;
                        //    if (ds.Tables[0].Rows[i]["pa"].ToString().Trim().Length == 0)
                        //        _PremiumInfo.InsTypeCode = "0";
                        //    else
                        //        _PremiumInfo.InsTypeCode = ds.Tables[0].Rows[i]["pa"].ToString().Trim();
                        //    _PremiumInfo.Description = UnicodeConvert.TCVN3ToUnicode(ds.Tables[0].Rows[i]["ghichu"].ToString().Trim());
                        //    _PremiumInfo.IsInitial = true;
                        //    _PremiumInfo.DateVal = Convert.ToDateTime("01/01/2000");
                        //    if (!_wcfPremium.Premium_Exist(0, _PremiumInfo.SIBookNo, _PremiumInfo.FromDate, _PremiumInfo.ToDate))
                        //        _wcfPremium.Premium_Insert(_PremiumInfo);
                        //}
                        #endregion
                    }
                    else if (_FileName.Contains("S53_DTL.DBF"))
                    {
                        #region Ket qua dong BHXH
                        //for (i = 0; i < ds.Tables[0].Rows.Count; i++)
                        //{

                        //    //Insert bang HRM_Premium:
                        //    _FundInfo = new SalaryFundInfo();
                        //    _FundInfo.BranchCode = ds.Tables[0].Rows[i]["madvi"].ToString().Trim();
                        //    _FundInfo.Month = Convert.ToDateTime(ds.Tables[0].Rows[i]["thang"].ToString().Substring(4, 2) + "/" + ds.Tables[0].Rows[i]["thang"].ToString().Substring(0, 4));
                        //    _FundInfo.Quater = ds.Tables[0].Rows[i]["quy"].ToString().Substring(4, 1) + "/" + ds.Tables[0].Rows[i]["quy"].ToString().Substring(0, 4);

                        //    //Lay du lieu thang truoc chuyen sang:
                        //    _dtLast = _wcfFund.SalaryFund_GetLastData(_FundInfo.Month.Month, _FundInfo.Month.Year, _FundInfo.BranchCode).Tables[0];
                        //    if (_dtLast.Rows.Count > 0)
                        //    {
                        //        _BHYT_ThuaKyTruoc = UISetting.GetDecimalNo(_dtLast.Rows[0]["SalaryFund_BHYTThua"].ToString());
                        //        _BHYT_ThieuKyTruoc = UISetting.GetDecimalNo(_dtLast.Rows[0]["SalaryFund_BHYTThieu"].ToString());
                        //        _BHTN_ThuaKyTruoc = UISetting.GetDecimalNo(_dtLast.Rows[0]["SalaryFund_BHTNThua"].ToString());
                        //        _BHTN_ThieuKyTruoc = UISetting.GetDecimalNo(_dtLast.Rows[0]["SalaryFund_BHTNThieu"].ToString());
                        //        _BHXH_ThuaKyTruoc = UISetting.GetDecimalNo(_dtLast.Rows[0]["SalaryFund_BHXHThua"].ToString());
                        //        _BHXH_ThieuKyTruoc = UISetting.GetDecimalNo(_dtLast.Rows[0]["SalaryFund_BHXHThieu"].ToString());
                        //    }
                        //    else
                        //    {
                        //        _BHYT_ThuaKyTruoc = 0;
                        //        _BHYT_ThieuKyTruoc = 0;
                        //        _BHTN_ThuaKyTruoc = 0;
                        //        _BHTN_ThieuKyTruoc = 0;
                        //        _BHXH_ThuaKyTruoc = 0;
                        //        _BHXH_ThieuKyTruoc = 0;
                        //    }

                        //    //Lay so tien da nop o bang UNC:
                        //    _PaidAmount = _wcfUNC.UNC_GetAmountPaid(_FundInfo.Month.Month, _FundInfo.Month.Year, _FundInfo.BranchCode);
                        //    _PaidAmount = _PaidAmount + _BHYT_ThuaKyTruoc + _BHTN_ThuaKyTruoc + _BHXH_ThuaKyTruoc;

                        //    //BHYT:
                        //    _FundInfo.BHYT_Amount = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["tqlyt"].ToString());
                        //    _FundInfo.BHYT_Employee = UISetting.GetIntNo(ds.Tables[0].Rows[i]["sld"].ToString());
                        //    _FundInfo.BHYT_HaveToPaid = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["pt_bhyt"].ToString());
                        //    _FundInfo.BHYT_Increase = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["bst_bhyt"].ToString());
                        //    _FundInfo.BHYT_Decrease = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["bsg_bhyt"].ToString());
                        //    _FundInfo.BHYT_KyTruocThua = _BHYT_ThuaKyTruoc;
                        //    _FundInfo.BHYT_KyTruocThieu = _BHYT_ThieuKyTruoc;
                        //    _FundInfo.BHYT_Sum = _FundInfo.BHYT_HaveToPaid + _FundInfo.BHYT_Increase - _FundInfo.BHYT_Decrease + _BHYT_ThieuKyTruoc - _BHYT_ThuaKyTruoc;
                        //    _FundInfo.BHYT_InterestAmount = 0;

                        //    if (_PaidAmount > _FundInfo.BHYT_Sum)
                        //    {
                        //        _BHYT_PaidAmount = _FundInfo.BHYT_Sum;
                        //        _AmountRemain = _PaidAmount - _BHYT_PaidAmount;
                        //    }
                        //    _FundInfo.BHYT_PaidAmount = _BHYT_PaidAmount;
                        //    if (_FundInfo.BHYT_PaidAmount <= _FundInfo.BHYT_Sum)
                        //        _FundInfo.BHYT_Thieu = _FundInfo.BHYT_Sum - _FundInfo.BHYT_PaidAmount;
                        //    else
                        //        _FundInfo.BHYT_Thua = _FundInfo.BHYT_PaidAmount - _FundInfo.BHYT_Sum;

                        //    //BHTN:
                        //    _FundInfo.BHTN_Amount = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["tqltn"].ToString());
                        //    _FundInfo.BHTN_Employee = UISetting.GetIntNo(ds.Tables[0].Rows[i]["sld"].ToString());
                        //    _FundInfo.BHTN_HaveToPaid = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["pt_bhtn"].ToString());
                        //    _FundInfo.BHTN_Increase = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["bst_bhtn"].ToString());
                        //    _FundInfo.BHTN_Decrease = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["bsg_bhtn"].ToString());
                        //    _FundInfo.BHTN_KyTruocThua = _BHTN_ThuaKyTruoc;
                        //    _FundInfo.BHTN_KyTruocThieu = _BHTN_ThieuKyTruoc;
                        //    _FundInfo.BHTN_Sum = _FundInfo.BHTN_HaveToPaid + _FundInfo.BHTN_Increase - _FundInfo.BHTN_Decrease + _BHTN_ThieuKyTruoc - _BHTN_ThuaKyTruoc;
                        //    _FundInfo.BHTN_InterestAmount = 0;

                        //    if (_AmountRemain > _FundInfo.BHTN_Sum)
                        //    {
                        //        _BHTN_PaidAmount = _FundInfo.BHTN_Sum;
                        //        _AmountRemain = _AmountRemain - _BHTN_PaidAmount;
                        //    }
                        //    _FundInfo.BHTN_PaidAmount = _BHTN_PaidAmount;
                        //    if (_FundInfo.BHTN_PaidAmount <= _FundInfo.BHTN_Sum)
                        //        _FundInfo.BHTN_Thieu = _FundInfo.BHTN_Sum - _FundInfo.BHTN_PaidAmount;
                        //    else
                        //        _FundInfo.BHTN_Thua = _FundInfo.BHTN_PaidAmount - _FundInfo.BHTN_Sum;

                        //    //BHXH:
                        //    _FundInfo.BHXH_Amount = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["tql"].ToString());
                        //    _FundInfo.BHXH_Employee = UISetting.GetIntNo(ds.Tables[0].Rows[i]["sld"].ToString());
                        //    _FundInfo.BHXH_HaveToPaid = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["pt_bhxh"].ToString());
                        //    _FundInfo.BHXH_Increase = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["bst_bhxh"].ToString());
                        //    _FundInfo.BHXH_Decrease = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["bsg_bhxh"].ToString());
                        //    _FundInfo.BHXH_KyTruocThua = _BHXH_ThuaKyTruoc;
                        //    _FundInfo.BHXH_KyTruocThieu = _BHXH_ThieuKyTruoc;
                        //    _FundInfo.BHXH_Sum = _FundInfo.BHXH_HaveToPaid + _FundInfo.BHXH_Increase - _FundInfo.BHXH_Decrease + _BHXH_ThieuKyTruoc - _BHXH_ThuaKyTruoc;
                        //    _FundInfo.BHXH_InterestAmount = 0;

                        //    _BHXH_PaidAmount = _AmountRemain;
                        //    _FundInfo.BHXH_PaidAmount = _BHXH_PaidAmount;
                        //    if (_FundInfo.BHXH_PaidAmount <= _FundInfo.BHXH_Sum)
                        //        _FundInfo.BHXH_Thieu = _FundInfo.BHXH_Sum - _FundInfo.BHXH_PaidAmount;
                        //    else
                        //        _FundInfo.BHXH_Thua = _FundInfo.BHXH_PaidAmount - _FundInfo.BHXH_Sum;

                        //    _FundInfo.IsApproved = 2;

                        //    if (_wcfFund.SalaryFund_CheckExist(0, Program.strBranchBHXH, _FundInfo.Quater, _FundInfo.Month) <= 0)
                        //        _wcfFund.SalaryFund_Insert(_FundInfo);
                        //}
                        #endregion
                    }
                    else if (_FileName.Contains("UNC.DBF"))
                    {
                        #region Ủy nhiệm chi
                        //for (i = 0; i < ds.Tables[0].Rows.Count; i++)
                        //{
                        //    //Insert bang HRM_Premium:
                        //    _UNCInfo = new UNCInfo();
                        //    _UNCInfo.BranchCode = ds.Tables[0].Rows[i]["madvi"].ToString().Trim();
                        //    _UNCInfo.No = ds.Tables[0].Rows[i]["sophieu"].ToString().Trim();
                        //    _UNCInfo.Date = Convert.ToDateTime(ds.Tables[0].Rows[i]["ngay"].ToString().Trim());
                        //    _UNCInfo.Quater = ds.Tables[0].Rows[i]["quy"].ToString().Substring(4, 1) + "/" + ds.Tables[0].Rows[i]["quy"].ToString().Substring(0, 4);
                        //    _UNCInfo.Month = UISetting.GetIntNo(ds.Tables[0].Rows[i]["thang"].ToString().Substring(4, 2));
                        //    _UNCInfo.Year = UISetting.GetIntNo(ds.Tables[0].Rows[i]["thang"].ToString().Substring(0, 4));
                        //    _UNCInfo.Content = ds.Tables[0].Rows[i]["noidung"].ToString().Trim();
                        //    _UNCInfo.Amount = UISetting.GetDecimalNo(ds.Tables[0].Rows[i]["tien_vnd"].ToString());
                        //    _UNCInfo.Discription = ds.Tables[0].Rows[i]["ghichus"].ToString().Trim();
                        //    if (!_wcfUNC.UNC_CheckExist(0, Program.strBranchBHXH, _UNCInfo.Date, _UNCInfo.No))
                        //        _wcfUNC.UNC_Insert(_UNCInfo);
                        //}
                        #endregion
                    }
                }
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
